package com.draw.cli.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;

import com.draw.cli.gui.img.IconManager;


public class MenuBar extends JMenuBar implements ActionListener {
	private static final long serialVersionUID = 5712067210894798021L;

	private static MenuBar instance = new MenuBar();

	public static MenuBar getInstance() {
		return instance;
	}
	
	private JMenu file;
	private JMenuItem home;
	private JMenuItem config;
	private JMenuItem quit;
	private JMenu ident;
	private JMenuItem login;
	private JMenuItem newUser;
	private JMenuItem refresh;
	private JMenu about;
	private JMenuItem help;
	private JMenuItem aboutitem;
	
	public MenuBar() {		
		this.file = new JMenu("Fichier");
		this.home = new JMenuItem("Accueil",IconManager.HOME_16);
		this.home.addActionListener(this);
		this.file.add(this.home);
		this.config = new JMenuItem("Configuration",IconManager.CONFIG_16);
		this.config.addActionListener(this);
		this.file.add(this.config);
		this.file.add(new JSeparator());
		this.quit = new JMenuItem("Quitter",IconManager.EXIT_16);
		this.quit.addActionListener(this);
		this.file.add(this.quit);
		this.add(this.file);
		this.ident = new JMenu("Identification");
		this.login = new JMenuItem("Connexion",IconManager.USER_16);
		this.login.addActionListener(this);
		this.ident.add(this.login);
		this.newUser = new JMenuItem("Créer un nouvel utilisateur",IconManager.ADDUSER_16);
		this.newUser.addActionListener(this);
		this.ident.add(this.newUser);
		this.ident.add(new JSeparator());
		this.refresh = new JMenuItem("Rafraichir");
		this.refresh.addActionListener(this);
		this.ident.add(this.refresh);
		this.add(this.ident);
		this.about = new JMenu("?");
		this.help = new JMenuItem("Aide");
		this.about.add(this.help);
		this.aboutitem = new JMenuItem("A propos");
		this.about.add(aboutitem);
		this.add(this.about);
	}

	public void actionPerformed(ActionEvent arg0) {
		if ( arg0.getSource().equals(this.quit)){
			Window.getInstance().exit();
		} else if ( arg0.getSource().equals(this.config)){
			Window.getInstance().setConfig();
		} else if ( arg0.getSource().equals(this.home)){
			Window.getInstance().setHome();
		} else if ( arg0.getSource().equals(this.login)){
			Window.getInstance().setLogin();
		} else if ( arg0.getSource().equals(this.newUser)){
			Window.getInstance().setNewUser();
		} else if ( arg0.getSource().equals(this.refresh)){
			Window.getInstance().refresh();
		} 
	}
	
	
}